All files / src/app/api/collections/[id]/dispositions/[itemId] route.ts

100% Statements 12/12
100% Branches 6/6
100% Functions 1/1
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18              6x 6x 6x 5x 5x 5x 4x 3x 3x    
import { NextRequest, NextResponse } from "next/server";
import { getSession } from "@/lib/auth";
import { getDb } from "@/lib/db";
import { requireApiItemCapability } from "@/server/dal/collection-access";
import { DispositionController } from "@/server/api/dispositions";
 
export async function DELETE(_req: NextRequest, { params }: { params: Promise<{ id: string; itemId: string }> }) {
  const { id, itemId } = await params;
  const session = await getSession();
  if (!session?.user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
  const db = getDb();
  const item = await requireApiItemCapability(db, itemId, session.user.id, "preferences:write");
  if (item instanceof NextResponse) return item;
  if (item.collectionId !== id) return NextResponse.json({ error: "Not found" }, { status: 404 });
  await DispositionController.fromDb(db).bringBack(itemId, session.user.id); // idempotent → 200
  return NextResponse.json({ message: "Brought back" });
}